package com.zbkj.crmeb.enums;

import java.util.Objects;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.constants.Constants;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 业务类型
 * @author daigb
 * @date:  2022-07-26 10:26
 */
public enum BusinessCodeEnum implements IEnum<Integer> {

	/**
	 * 商户余额预警
	 */
    MERCHANT_ACCOUNT_WARN(1, "商户余额低于5000预警"),

    ;

    private final Integer code;
    private final String msg;

    BusinessCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static BusinessCodeEnum valueOf(Integer code) {
        for (BusinessCodeEnum value : values()) {
            if (code.equals(value.getCode())) {
                return value;
            }
        }
        return BusinessCodeEnum.MERCHANT_ACCOUNT_WARN;
    }

    @Override
    @JsonValue
    public Integer getValue() {
        return code;
    }

    public static BusinessCodeEnum getEnumByCode(Integer code) {
        for (BusinessCodeEnum value : values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value;
            }
        }
        return MERCHANT_ACCOUNT_WARN;
    }

    public static String getMsgByCode(Integer code) {
        for (BusinessCodeEnum value : values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value.msg;
            }
        }
        return MERCHANT_ACCOUNT_WARN.msg;
    }
}

